import {
  fileUrl
} from "../../network/index"
import {
  uploadPicture
} from "../../../utils/upload"
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    isShow: false,
    status: false,
    memo: "",
    price: "",
    image: []
  },

  /**
   * 组件的方法列表
   */
  methods: {
    uploadFile() {
      let data = this.data.image
      uploadPicture().then(v => {

        v.forEach(item => {
          data.push(item.url)
        })
        this.setData({
          image: data
        })

      })
      console.log(data)

    },
    delPicture(e) {
      //获取图片的下标
      let {
        index
      } = e.currentTarget.dataset
      let _this = this
      wx.showModal({
        title: "提示",
        content: "是否删除图片",
        success(res) {
          if (res.confirm) {
            let image = _this.data.image.filter((item, i) => {
              return !index == i
            })
            _this.setData({
              image
            })

            wx.showToast({
              title: '删除成功',
            })
          } else if (res.cancel) {
            wx.showToast({
              title: '取消删除',
              icon: "none"
            })
          }
        }
      })

    },
    //预览图片
    prePicture(e) {
      let current = e.currentTarget.dataset
      wx.previewImage({
        urls: this.data.image,
        current: current.image
      })
    },
    close() {
      this.triggerEvent('closePopup')
    },
    inputPrice(e) {
      this.setData({
        price: e.detail.value
      })
    },

    inputMemo(e) {
      this.setData({
        memo: e.detail.value
      })
    },
    //发射事件
    submit() {
      let _this = this
      wx.showModal({
        title: '提示',
        content: '是否提交该流程',
        success(res) {
          if (res.confirm) {
            _this.triggerEvent('submitPlan', {
              memo: _this.data.memo,
              price: _this.data.price,
              image: _this.data.image
            })
          } else if (res.cancel) {
            wx.showToast({
              title: '取消成功',
            })
          }
        }
      })

    },
    consent() {
      this.setData({
        status: true
      })
      this.submit()
    },
    refuse() {},
  }
})